<!--
  @author heguanghua
  @since 2019/06/12 11:57
-->
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="common/common::jscss"/>
<body>


<div class="layui-fluid">

    <blockquote class="layui-crumb">
        渠道管理>
        <a lay-href="/channel/list.action">渠道管理</a>>
        <a th:href="'/channel/detail.action?channelId='+${obj.channelId}">[[${obj.name}]]</a>>
        <zmn th:text="佣金设置">佣金设置</zmn>
    </blockquote>

    <div class="layui-card">

        <div th:replace="channel/_tab::tab"></div>

        <fieldset class="layui-elem-field">
            <div class="layui-field-box" style="color: #9F9F9F;">
                渠道信息处，接入信息为：渠道时，才可配置佣金，同时佣金设置才生效
            </div>
        </fieldset>

        <div class="layui-card-body">
            <input type="hidden" id="channelId" name="channelId" th:value="${obj.channelId}"/>
            <input type="hidden" id="relateId" name="relateId" th:value="${commissionSettleRule.relateId}"/>

            <form method="POST" action="" class="layui-form" lay-filter="zmn-form">
                <div class="layui-form-item" id="settleDiv">
                    <label class="layui-form-label layui-form-required">佣金结算：</label>
                    <div class="layui-input-inline" style="width:300px">
                        <input type="radio" name="settle" lay-filter="settle" value="2"
                               th:checked="${commissionSettleRule.settle == 2}" title="开启" lay-verify="required">
                        <input type="radio" name="settle" lay-filter="settle" value="1"
                               th:checked="${commissionSettleRule.settle == 1}" title="关闭" lay-verify="required">
                    </div>

                    <div id="deductDiv" th:style="|display: ${(commissionSettleRule.relateId == null || commissionSettleRule.settle == 2) ? '':'none'}|">
                        <label class="layui-form-label layui-form-required">坐扣：</label>
                        <div class="layui-input-inline" style="width:300px">
                            <input type="radio" id="deduct2" name="deduct" value="2" lay-filter="deduct"
                                   th:checked="${commissionSettleRule.deduct == 2}" title="是" lay-verify="required">
                            <input type="radio" name="deduct" value="1" lay-filter="deduct"
                                   th:checked="${commissionSettleRule.deduct == 1}" title="否" lay-verify="required">
                        </div>
                    </div>
                </div>

            </form>

            <table class="layui-hide" id="zmn-table" lay-filter="zmn-table">
                <thead>
                <tr>
                    <th lay-data="{field:'servCategId', width:200, unresize:true, align:'center'}">服务分类ID</th>
                    <th lay-data="{field:'servCategName', width:200, unresize:true, align:'center'}">服务分类名称</th>
                    <th lay-data="{field:'gz', width:200, unresize:true, align:'center'}">规则</th>
                    <th lay-data="{field:'js', width:200, unresize:true, align:'center'}">基数</th>
                    <th lay-data="{field:'bl', width:200, unresize:true, align:'center'}">比例/金额</th>

                    <th lay-data="{field:'commissionTypeNew', width:100, unresize:true, align:'left', hide:true}">佣金类型</th>
                    <th lay-data="{field:'baseTypeNew', width:100, unresize:true, align:'left', hide:true}">佣金基数</th>
                    <th lay-data="{field:'commissionNew', width:100, unresize:true, align:'left', hide:true}">佣金</th>
                    <th lay-data="{field:'effectiveTime', width:200, unresize:true, align:'left', hide:true}">生效时间</th>
                    <th lay-data="{field:'updateTime', width:300, unresize:true, align:'center'}">最近修改人/时间</th>
                    <th lay-data="{field:'操作', unresize:true, align:'center', fixed:'right', toolbar: '#zmn-table-bar'}">操作</th>

                </tr>
                </thead>
                <tbody>
                <tr th:each="commission:${commissions}">
                    <td th:text="${commission.servCategId}"></td>
                    <td th:text="${commission.servCategName}"></td>
                    <td th:text="${commission.commissionTypeNew == null ? '---' : (commission.commissionTypeNew == 1 ? '按比例' : '按金额')}"></td>
                    <td th:text="${commission.baseTypeNew == null || commission.commissionTypeNew == 2 ? '---' : T(com.zmn.plat.common.dictionary.ChannelCommissionBaseTypeEnum).getName(commission.baseTypeNew)}"></td>
                    <td th:text="${commission.commissionNew == null ? '---' : (commission.commissionTypeNew == 1 ? commission.commissionNew + '%' : (commission.commissionNew / 100) + '元/单')}"></td>

                    <td th:text="${commission.commissionTypeNew}"></td>
                    <td th:text="${commission.baseTypeNew}"></td>
                    <td th:text="${commission.commissionNew == null || commission.commissionTypeNew == 1 ? commission.commissionNew : commission.commissionNew / 100}"></td>
                    <td th:text="${#dates.format(commission.effectiveTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    <td th:text="|${commission.updater == null ? '' : commission.updater + '/' + #dates.format(commission.updateTime, 'yyyy-MM-dd HH:mm:ss')}|"></td>
                </tr>
                </tbody>
            </table>

            <script type="text/html" id="zmn-table-tool">
                <div class="layui-btn-container">
                    <div class="layui-btn-group" th:if="${(#authPermit.checkPermit('/channel/commission/addEdit.action') || (#authPermit.checkPermit('/channel/add.action') && addFlag == '1')) && #strings.contains(obj.accessIdentity == null ? '':obj.accessIdentity, '1')}">
                        <button class="layui-btn layui-btn-sm" lay-event="batchSet">统一佣金设置</button>
                    </div>
                </div>
            </script>
        </div>
    </div>

</div>
</body>
</html>

<script id="modifyHtml" type="text/html">
    <form method="POST" action="" class="layui-form" lay-filter="zmn-form">
        <input type="hidden" name="servCategId" value="{{d.servCategId}}"/>
        <input type="hidden" name="servCategName" value="{{d.servCategName}}"/>
        <!--<input type="hidden" name="commissionType" value="{{d.commissionType}}"/>-->
        <!--<input type="hidden" name="commissionCurrent" value="{{d.commissionCurrent}}"/>-->
        <!--<input type="hidden" name="baseType" value="{{d.baseType}}"/>-->
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">佣金规则：</label>
            <div>
                <input type="radio" lay-filter="commissionTypeNew" name="commissionTypeNew" value="1" title="按比例返佣" {{d.commissionTypeNew == 1 ? 'checked' : ''}}>
                <input type="radio" lay-filter="commissionTypeNew" name="commissionTypeNew" value="2" title="按固定金额返佣" {{d.commissionTypeNew == 2 ? 'checked' : ''}}>
            </div>
        </div>
        <div class="layui-form-item" id="baseTypeNew_id">
            <label class="layui-form-label layui-form-required">佣金基数：</label>
            <div>
                <input type="radio" lay-filter="baseTypeNew" name="baseTypeNew" value="1" title="渠道收款" {{d.baseTypeNew == 1 ? 'checked' : ''}}>
                <input type="radio" lay-filter="baseTypeNew" name="baseTypeNew" value="2" title="订单收入" {{d.baseTypeNew == 2 ? 'checked' : ''}}>
<!--                <input type="radio" lay-filter="baseTypeNew" name="baseTypeNew" value="3" title="绩效基数金额" {{d.baseTypeNew == 3 ? 'checked' : ''}}>-->
                <input type="radio" lay-filter="baseTypeNew" name="baseTypeNew" value="4" title="外部价" {{d.baseTypeNew == 4 ? 'checked' : ''}}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required type1">佣金比例：</label>
            <label class="layui-form-label layui-form-required type2">固定金额：</label>
            <div class="layui-input-inline" style="width:200px">
                <input type="text" id="commissionNew" name="commissionNew" value="{{d.commissionNew}}" placeholder="佣金" lay-verify="required|number" lay-verType="tips" autocomplete="off" class="layui-input" maxlength="6"/>
            </div>
            <span class="type1" style="width: auto; color: #9F9F9F;">% 比例范围 0~12%</span>
            <span class="type2" style="width: auto; color: #9F9F9F;">元 金额范围0~30元</span>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">生效时间：</label>
            <div class="layui-input-inline" style="width:200px">
                <input type="text" id="effectiveTime" name="effectiveTime" value="{{d.effectiveTime}}" lay-verify="required" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <span style="color: red">如生效时间小于当前时间，将立即生效</span>
        </div>
        <div class="layui-form-item submit">
            <div style="text-align: center">
                <button class="layui-btn" lay-submit lay-filter="zmn-form-submit">提交</button>
                <a class="layui-btn layui-btn-primary" onclick="layer.close(childIndex);">取消</a>
            </div>
        </div>
    </form>
</script>

<script type="text/javascript" th:inline="javascript">

    var json = {
        addFlag: [[${addFlag}]],
        obj: [[${obj}]],
        hasViewEdit: [[${(#authPermit.checkPermit('/channel/commission/addEdit.action') || (#authPermit.checkPermit('/channel/add.action') && addFlag == '1')) && #strings.contains(obj.accessIdentity == null ? '':obj.accessIdentity, '1')}]]
    };

    let childIndex;
    layui.config({
        base: "/static/lay/",
        version: 201908231434
    }).extend({
        index: "lib/index",
        channel_commission: "channel/zmn.plat.channel.commission",
    }).use(['index', 'channel_commission']);

</script>


<script type="text/html" id="zmn-table-bar">
    {{#if(json.hasViewEdit){ }}
    <a style="color: #00a0e9" lay-event="modify">设置佣金</a>
    {{#}}}
</script>